'use strict';
const db = uniCloud.database()
const $ = db.command.aggregate
exports.main = async (event, context) => {
	
	// let label = await db.collection("label").get()
	
	
	const {
		user_id:"6053212f73c0390001c4a9eb",
		type
	}= event
	let matchObj = {}
	if(type!=='all'){
		matchObj = {
			current:true
		}
	}
	
	let userInfo = await db.collection('user').doc(user_id).get()
	userInfo = userInfo.data[0]
	
	let label = await db.collection("label")
	.aggregate()
	.addFields({
		current:$.in(['$_id',$.ifNull([userInfo.label_ids,[]])])
	})
	.match(matchObj)
	.end()
	
	//event为客户端上传的参数
	console.log('event : ', event)
	
	//返回数据给客户端
	return {
		code:200,
		message:"成功",
		data:label.data
	}
};
